﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace CSharpAlgorithm
{
    class ThreeNPlusOne
    {

        private Dictionary<int, int> resultList = new Dictionary<int, int>();
        private List<int> thisSolution = new List<int>();
        public ThreeNPlusOne()
        {

            int T = GetConsole.GetInt();
            for (int i = 0; i < T; i++)
            {
                int a = GetConsole.GetInt();
                int b = GetConsole.GetInt();

                if (a > b)
                {
                    int buf = b;
                    b = a;
                    a = buf;
                }
                int maxNum = 0;
                for (int j = a; j <= b; j++)
                {
                    int result = GetResult(j);
                    if (result > maxNum)
                    { maxNum = result; }
                }
                Console.WriteLine("{0} {1} {2}", a, b, maxNum);
                //Console.ReadLine();
            }

        }

        private int GetResult(int val)
        {
            thisSolution.Clear();
            int count = 0;
            while (val != 1)
            {
                //값이 이미 존재할 경우
                if (resultList.ContainsKey(val))
                {
                    count += resultList[val];
                    break;
                }
                count++;
                thisSolution.Add(val);
                if (val % 2 == 0)
                {
                    val = val / 2;
                }
                else
                {
                    val = val * 3 + 1;
                }
            }
            //현재 솔루션 저장
            for (int i = 0; i < thisSolution.Count; i++)
            {
                resultList.Add(thisSolution[i], count - i);
            }
            return count;
        }
    }
}
